package com.itheima.d4_synchronized;

public class Account {
    private String cardId;
    private int money;

    public Account() {
    }

    public Account(String cardId, int money) {
        this.cardId = cardId;
        this.money = money;
    }

    public static void test(){
        synchronized (Account.class){}
    }

    public void drawMoney(double money){
        String name =Thread.currentThread().getName();
        synchronized (this) {
            if(this.money>=money){
                System.out.println(name+"成功取走"+money);
                this.money -=money;
                System.out.println(name+"取钱后剩余"+this.money);
            }else {
                System.out.println(name+"来取钱失败");
            }
        }
    }

    public String getCardId() {
        return cardId;
    }

    public void setCardId(String cardId) {
        this.cardId = cardId;
    }

    public int getMoney() {
        return money;
    }

    public void setMoney(int money) {
        this.money = money;
    }
}
